<template>
  <div>
    <BasicTable @register="registerTable" :rowSelection="rowSelection">
      <template #tableTitle>
        <a-button type="primary" preIcon="ant-design:export-outlined" @click="onExportXls"> 导出</a-button>
        <j-upload-button type="primary" preIcon="ant-design:import-outlined" @click="onImportXls">导入</j-upload-button>
      </template>
      <!-- 展示订单号 -->
      <template #orderNo="{ record }">
        <Row :gutter="[24, 24]" class="order-no">
          <Col :span="5">
            <Tag color="blue">转账</Tag>
          </Col>
          <Col :span="19">
            <Tooltip placement="topLeft">
              <template #title>
                <span>{{ record.transferNo }}</span>
              </template>
              <span class="order-no-data">{{ record.transferNo }}</span>
            </Tooltip>
          </Col>
        </Row>
        <Row :gutter="[24, 24]">
          <Col :span="5">
            <Tag color="green">商户</Tag>
          </Col>
          <Col :span="19">
            <Tooltip placement="topLeft">
              <template #title>
                <span>{{ record.mchOrderNo }}</span>
              </template>
              <span class="order-no-data">{{ record.mchOrderNo }}</span>
            </Tooltip>
          </Col>
        </Row>
      </template>
      <template #action="{ record }">
        <TableAction :actions="getActions(record)" />
      </template>
    </BasicTable>
    <DetailModal @register="register" />
  </div>
</template>
<script lang="ts" name="PayTransferOrder" setup>
  import { ref, onUnmounted } from "vue"
  import { BasicTable, TableAction } from "/@/components/Table"
  import { useModal } from "/@/components/Modal"
  import { useDrawer } from "/@/components/Drawer"
  import DetailModal from "./DetailModal.vue"
  import { useGlobSetting } from "/@/hooks/setting"
  import { columns, searchFormSchema } from "./transferOrder.data"
  import { Url } from "/@/api/pay"
  import * as Api from "/@/api/pay"
  import { useListPage } from "/@/hooks/system/useListPage"
  import { useMessage } from "/@/hooks/web/useMessage"
  import { Tag, Row, Col, Tooltip } from "ant-design-vue"
  const { createMessage } = useMessage()
  const glob = useGlobSetting()
  const isScanCode = ref(false)
  const timeInter = ref<any>(null)
  const [register, { openDrawer: openDetail }] = useDrawer()
  // 列表页面公共参数、方法
  const { prefixCls, onExportXls, onImportXls, tableContext } = useListPage({
    designScope: "pay-transfer-order",
    tableProps: {
      title: "转账列表",
      api: Api.pageTransferOrder,
      columns: columns,
      actionColumn: {
        width: 100,
        title: "操作",
        dataIndex: "action",
        fixed: "right",
        slots: { customRender: "action" },
      },
      formConfig: {
        schemas: searchFormSchema,
        fieldMapToTime: [["fieldTime", ["beginDate", "endDate"], "YYYY-MM-DD HH:mm:ss"]],
      },
    },
    exportConfig: {
      name: "转账列表",
      url: Url.transOrderExport,
    },
    importConfig: {
      url: Url.transOrderImport,
    },
  })

  const [registerTable, { reload }, { rowSelection, selectedRowKeys }] = tableContext

  /**
   * 查看
   */
  function handleDetail(record) {
    openDetail(true, {
      record,
      isUpdate: true,
    })
  }
  /**
   * 操作列定义
   * @param record
   */
  function getActions(record) {
    return [
      {
        label: "查看",
        onClick: handleDetail.bind(null, record),
        // ifShow: record.sendStatus == 0
      },
    ]
  }

  onUnmounted(() => {
    clearInterval(timeInter.value) //销毁
    timeInter.value = null
  })

  const handleQrCodeSuccess = () => {
    clearInterval(timeInter.value)
  }
</script>

<style>
  .order-no {
    margin-bottom: 5px;
  }
  .order-no-data {
    float: left !important;
    text-align: left;
    border: 1px;
    width: 150px;
    overflow: hidden;
    margin-left: 5px;
    white-space: nowrap;
    text-overflow: ellipsis;
  }
</style>
